package net.hn.hnms.biz.mine.group.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.hn.hnms.biz.api.safety.monitor.model.ComprehensiveScore;
import net.hn.hnms.biz.api.safety.monitor.model.GroupComprehensiveScore;
import net.hn.hnms.biz.mine.domain.vo.EffectiveProductionTimeMonthlyStatisticsVo;
import net.hn.hnms.biz.mine.domain.vo.EffectiveProductionTimeVo;
import net.hn.hnms.biz.mine.group.service.GroupService;
import net.hn.hnms.biz.mine.service.GasService;
import net.hn.hnms.sys.common.core.constant.MineBaseConstants;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.utils.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Author: PanSX
 * Date: 2023/4/17 15:58
 */
@RestController
@RequestMapping("group/mine/")
@Api(value = "煤矿信息控制器-集团端", tags = {"煤矿信息控制器-集团端"})
public class GroupController {
    @Autowired
    private GasService gasService;

    //集团端服务
    @Resource
    private GroupService groupService;

    @GetMapping("getComprehensiveScore")
    @ApiOperation("各矿评分")
    public R<List<GroupComprehensiveScore>> getComprehensiveScore(String companyCode) {
        List<GroupComprehensiveScore> list = new ArrayList<>();
        for (String key : MineBaseConstants.mineMap.keySet()) {
            MineBaseConstants.Mine mine = MineBaseConstants.mineMap.get(key);
            if (StringUtils.isNotBlank(companyCode)&&!mine.getCompanyCode().equals(companyCode)) {
                continue;
            }
            GroupComprehensiveScore score = new GroupComprehensiveScore();
            BeanUtils.copyProperties(mine, score);
            ComprehensiveScore score1 = gasService.score(score.getMineCode());
            BeanUtils.copyProperties(score1, score);
            list.add(score);
        }
        return R.ok(list);
    }
    /**
     * 大屏-矿井有效生产时长
     */
    @ApiOperation("大屏-矿井有效生产时长")
    @GetMapping("getEffectiveProductionTimeList")
    public R<List<EffectiveProductionTimeVo>> getEffectiveProductionTimeList(){

        return R.ok(groupService.getEffectiveProductionTimeList());

    }

    /**
     * 大屏-矿井有效生产时长月统计
     */
    @ApiOperation("大屏-矿井有效生产时长月统计")
    @GetMapping("getEffectiveProductionTimeMonthlyStatisticsByCode")
    public R<EffectiveProductionTimeMonthlyStatisticsVo> getEffectiveProductionTimeMonthlyStatistics(@ApiParam(value = "煤矿编码") String mineCode) {

        EffectiveProductionTimeMonthlyStatisticsVo timeMonthlyStatisticsVo = groupService.getEffectiveProductionTimeMonthlyStatistics(mineCode);
        if (timeMonthlyStatisticsVo == null) {
            return R.fail(new EffectiveProductionTimeMonthlyStatisticsVo());
        }
        return R.ok(timeMonthlyStatisticsVo);

    }

}
